﻿#region Copyright Notice
// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 
#endregion
using System;
using System.Diagnostics;
using System.Xml.Serialization;

namespace AbstractClass.Collections.Graph
{
    /// <summary>
    /// Represents an edge in a <see cref="Graph&lt;T&gt;"/>.
    /// </summary>
    /// <typeparam name="T">The type of the value associated with vertex nodes.</typeparam>
    [Serializable]
    [DebuggerDisplay("{Source} -> {Destination}")]
    public class GraphEdge<T>
    {
        [NonSerialized] private Graph<T> _parent;

        /// <summary>
        /// Initializes a new instance of the <see cref="GraphEdge&lt;T&gt;"/> class.
        /// </summary>
        public GraphEdge()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GraphEdge&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="from">Source node.</param>
        /// <param name="to">Destination node.</param>
        public GraphEdge(GraphNode<T> from, GraphNode<T> to)
            : this(from, to, 0)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GraphEdge&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="from">Source node.</param>
        /// <param name="to">Destination node.</param>
        /// <param name="cost">The cost associated with the edge.</param>
        public GraphEdge(GraphNode<T> from, GraphNode<T> to, int cost)
        {
            Source = from;
            Destination = to;
            Cost = cost;
        }

        /// <summary>
        /// Gets or sets the owner <see cref="Graph&lt;T&gt;"/> of this instance.
        /// </summary>
        /// <value>The owner <see cref="Graph&lt;T&gt;"/>.</value>
        [XmlIgnore]
        public Graph<T> Owner
        {
            get { return _parent; }
            set { _parent = value; }
        }

        /// <summary>
        /// Gets or sets the source node of this instance.
        /// </summary>
        /// <value>The source node.</value>
        public GraphNode<T> Source { get; set; }

        /// <summary>
        /// Gets or sets the destination node of this instance.
        /// </summary>
        /// <value>The destination node.</value>
        public GraphNode<T> Destination { get; set; }

        /// <summary>
        /// Gets or sets the cost associated with this instance.
        /// </summary>
        /// <value>The cost associated with this instance.</value>
        public int Cost { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is a directed edge.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is directed; otherwise, <c>false</c>.
        /// </value>
        public bool IsDirected { get; set; }
    }
}